﻿using System;
using BO.Management.QueryBuilder;
using CrystalDecisions.Enterprise;


namespace BO.Management
{
    public class InstanceProvider : BaseInfoObjectProvider<InfoObject>
    {
        /// <summary>
        /// Default constructor required the LogonProvider used to connect to BO Cms
        /// </summary>
        /// <param name="logonProvider"></param>
        public InstanceProvider(LogonProvider logonProvider)
            : base(logonProvider)
        {

        }

        public override void AddSpecificFilter()
        {
            this.AddFilterToInstance(true);
        }


        public virtual void AddStartTime(DateTime start)
        {
            start = start.ToUniversalTime();
            this.QueryBuilder.AddParameter<DateTime>(InfoStoreFieldNames.InstanceStartTime, OperatorType.GreatherOrEqual, start);
        }

        public virtual void AddEndTime(DateTime start)
        {
            start = start.ToUniversalTime();
            this.QueryBuilder.AddParameter<DateTime>(InfoStoreFieldNames.InstanceStartTime, OperatorType.LessOrEqual, start);
        }

        public virtual void AddOutComeStatusSuccess()
        {
            this.QueryBuilder.AddParameter<Int32>(InfoStoreFieldNames.InstanceStatus, OperatorType.Equal, (Int32)CeScheduleOutcome.ceOutcomeSuccess);
        }

        public virtual void AddOutComeStatusFailure()
        {
            this.QueryBuilder.AddParameter<Int32>(InfoStoreFieldNames.InstanceStatus, OperatorType.Greather, (Int32)CeScheduleOutcome.ceOutcomeSuccess);
        }



        public override ObjectKind Kind
        {
            get { return ObjectKind.Instance; }
        }

        public void AddOutComeStatusPending()
        {
            this.QueryBuilder.AddParameter<Int32>(InfoStoreFieldNames.InstanceStatus, OperatorType.Equal, (Int32)CeScheduleOutcome.ceOutcomePending);
        }
    }
}
